package jdk8;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author oldliu
 * @since 1.0
 */
public class BankTest {
    public static void main(String[] args) {
        List<Bank> banks = Arrays.asList(new Bank("1", "liu1", "hefei", Math.random() * 1000), new Bank("2", "liu2", "beijing", Math.random() * 1000), new Bank("3", "liu3", "hefei", Math.random() * 1000), new Bank("3", "老刘", "anqing", Math.random() * 1000), new Bank("4", "老马", "hefei", Math.random() * 1000), new Bank("5", "小宋", "anqing", Math.random() * 1000), new Bank("6", "老吴", "hefei", Math.random() * 1000), new Bank("7", "小张", "huaibei", Math.random() * 1000));
        //1:遍历
        banks.forEach(System.out::println);
        //2:每个账号扣费5元
        System.out.println("2:每个账号扣费5元");
        //banks.forEach(x->x.setMoney(x.getMoney()-5));
        banks.forEach(x->{
            if(x.getMoney()<500)
                return;
            x.setMoney(x.getMoney()-5);
        });
        banks.forEach(System.out::println);

        System.out.println("统计一下合肥地区的账号，把他独立放到一个集合中");
        List<Bank> hefei = banks.stream().filter(x -> x.getCity().equals("hefei")).collect(Collectors.toList());
        System.out.println(hefei);
        System.out.println(">统计不同城市账户的人数，放入Map：");
        Map<String, Long> collect = banks.stream().collect(Collectors.groupingBy(x -> x.getCity(), Collectors.counting()));
        System.out.println(collect);
    }
}
